package com.hq.ims.home.controller;

import com.hq.ims.data.entityenum.*;
import com.hq.ims.data.interiorenum.EnumInsideFindDataScore;
import com.hq.ims.data.service.BaseCompanyService;
import com.hq.ims.data.utils.LocalConstant;
import com.hq.utils.util.ListUtils;
import com.hq.utils.vo.ReturnVo;
import com.hq.utils.vo.SelectVo;
import com.hq.web.annotations.GetJsonValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 **/
@Api(tags = "枚举选择")
@RestController
@RequestMapping(value = LocalConstant.SYS_TYPE_PUBLIC_URL_PREFIX + "/enum/select")
public class EnumSelectController {

    @Resource
    private BaseCompanyService baseCompanyService;


    @ApiOperation(value = "获取通知渠道", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getNoticeType", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<SelectVo>> getNoticeType() {
        List<SelectVo> list = Arrays.stream(EnumMessageChannel.values()).map(d -> new SelectVo(d.name(), d.getValue())).collect(Collectors.toList());
        return ReturnVo.buildSuccess(list);
    }

    @ApiOperation(value = "获取审核状态", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getAuditStatus", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<SelectVo>> getAuditStatus(
            @GetJsonValue(required = false) List<String> needAuditStatusList,
            @GetJsonValue(required = false) List<String> excludeAuditStatusList
    ) {
        List<SelectVo> list = Arrays.stream(EnumAuditStatus.values()).map(d -> new SelectVo(d.name(), d.getValue())).collect(Collectors.toList());
        if (ListUtils.isExistsEle(needAuditStatusList)) {
            list = list.stream().filter(d -> needAuditStatusList.contains(d.getId())).collect(Collectors.toList());
        } else if (ListUtils.isExistsEle(excludeAuditStatusList)) {
            list = list.stream().filter(d -> !excludeAuditStatusList.contains(d.getId())).collect(Collectors.toList());
        }
        return ReturnVo.buildSuccess(list);
    }

    @ApiOperation(value = "获取账号状态", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getAccountStatus", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<SelectVo>> getAccountStatus() {
        List<SelectVo> list = Arrays.stream(EnumAccountStatus.values()).map(d -> new SelectVo(d.name(), d.getValue())).collect(Collectors.toList());
        return ReturnVo.buildSuccess(list);
    }

    @ApiOperation(value = "获取公司级别", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getCompanyLv", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<SelectVo>> getCompanyLv() {
        List<SelectVo> list = Arrays.stream(EnumCompanyLevel.values())
                .map(d -> new SelectVo(d.name(), d.getValue()))
                .collect(Collectors.toList());
        return ReturnVo.buildSuccess(list);
    }

    @ApiOperation(value = "获取查找数据范围", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getFindDataScope", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<SelectVo>> getFindDataScope() {
        List<SelectVo> list = Arrays.stream(EnumInsideFindDataScore.values())
                .map(d -> new SelectVo(d.name(), d.getValue()))
                .collect(Collectors.toList());
        return ReturnVo.buildSuccess(list);
    }

    @ApiOperation(value = "获取业务key", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getBusKey", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<SelectVo>> getBusKey() {
        List<SelectVo> list = Arrays.stream(EnumBusKey.values())
                .map(d -> new SelectVo(d.name(), d.getValue()))
                .collect(Collectors.toList());
        return ReturnVo.buildSuccess(list);
    }

}
